﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LogicServer.Bugs;
using CommonCs;
using System.Data;
using LogicServer;

namespace BugSysSolution.RequestAjaxPage
{
    public partial class MainPageAjaxPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String tag = Request["tag"] ?? String.Empty;
            if (tag == "getbuglist")
            {
                GetAllBugListByType();
            }
            if (tag == "ajaxpage")
            {
                GetBugListByIndex();
            }
            
        }


        private static int type = 0;

        private void GetAllBugListByType()
        {
            String tag = Request["bugtype"] ?? String.Empty;
            type = Convert.ToInt32(tag);
            BugLogic bl = new BugLogic();

            DataTable dt = bl.GetBugsByType(Convert.ToInt32(tag));
            if (dt == null)
            {
                Response.Write(null);
                return;
            }

            Response.Write(Common.DataTableToJson(bl.GetBugsByType(Convert.ToInt32(tag))));
        }

        public void GetBugListByIndex()
        {
            String index = Request["index"] ?? String.Empty; 
            String size = Request["size"] ?? String.Empty;
            BugLogic bl = new BugLogic();
            DataTable dt = bl.GetBugsByIndex(Convert.ToInt32(index) - 1, Convert.ToInt32(size), type);
            if (dt == null)
            {
                Response.Write(null);
                return;
            }
            Response.Write(Common.DataTableToJson(bl.GetBugsByIndex(Convert.ToInt32(index) - 1, Convert.ToInt32(size), type)));
        }
    }
}